package com.patterns.proxy.generalProxyPlayer;

/**
 * Created by Xiao Yiyun on 2017/4/22.
 * 普通代理
 * 一个游戏玩家的实现类
 */
class GamePlayer implements IGamePlayer {
    //构造函数限制谁能创建对象，并同时传递姓名
    //只能通过代理类访问
    //而客户端无法绕过代理类直接访问实现类
    private String name = "";
    public GamePlayer(GamePlayerProxy gamePlayerProxy, String name) throws Exception {
        if (gamePlayerProxy == null) {
            throw new Exception("不能创建真实角色");
        } else {
            this.name = name;
        }
    }
    //实现业务方法
    public void login(String user, String pwd) {
        System.out.println("账户为" + user + "的用户" + this.name + "登录成功");
    }

    public void killBoss() {
        System.out.println(this.name + "正在打怪");
    }

    public void upGrade() {
        System.out.println(this.name + "又升了一级");
    }
}
